<script setup lang="ts">
  import { CodeScanSetData } from '../../../types'
  import { PropType, ref, watch } from 'vue'

  const props = defineProps({
    set: Object as PropType<CodeScanSetData>,
  })

  const emits = defineEmits<{
    (e: 'update', value: CodeScanSetData): void
  }>()

  // 数据源
  const set = ref<CodeScanSetData | null>(null)

  // 通知父组件更新
  const onUpdate = () => {
    emits('update', { ...set.value })
  }

  watch(
    () => props.set,
    (value) => {
      set.value = { ...value }
    },
    { deep: true, immediate: true },
  )
</script>

<template>
  <div>
    <el-form label-position="right" label-width="70px">
      <el-form-item class="mt-10" label="标题">
        <el-input
          v-model.trim="set.name"
          maxlength="10"
          placeholder="请输入标题"
          @input="onUpdate"
        />
      </el-form-item>
      <el-form-item class="mt-10" label="标题位置">
        <el-radio-group v-model="set.align" @change="onUpdate">
          <el-radio :value="1">左对齐</el-radio>
          <el-radio :value="2">左右居中</el-radio>
          <el-radio :value="3">右对齐</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item class="mt-10" label="显示状态">
        <div class="flex-center-5">
          <el-switch v-model="set.show" @change="onUpdate" />
          <span v-if="set.show">显示</span>
          <span v-else>隐藏</span>
        </div>
      </el-form-item>
      <el-form-item label="视频代码">
        <el-input
          v-model.trim="set.val"
          :rows="5"
          placeholder="请输入内容"
          type="textarea"
          @input="onUpdate"
        />
        <div style="color: #999">各大视频网站均可复制通用代码</div>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped lang="scss">
  .mt-10 {
    margin-bottom: 10px;
  }

  .flex-center-5 {
    display: flex;
    align-items: center;
    gap: 5px;
  }
</style>
